<template>
  <basic-container>
    <el-row>
      <el-col :span="15">
        <span>{{ schoolName }}</span>
      </el-col>
      <el-col :span="9">
        <el-select
          v-model="projectId"
          placeholder="请选择项目"
          size="small"
          style="width: 300px"
          clearable
        >
          <el-option
            v-for="item in projectOptions"
            :key="item.projectId"
            :label="item.projectName"
            :value="item.projectId"
          >
          </el-option>
        </el-select>
        <el-button
          type="primary"
          size="small"
          @click="searchProjectData"
          style="margin-left: 10px"
        >
          搜索
        </el-button>
        <el-button type="primary" size="small" @click="handleDown">
          查看详情
        </el-button>
      </el-col>
    </el-row>
    <div style="border-bottom: 5px solid #f0f0f0; margin-bottom: 20px" />
    <el-row v-if="isLoad">
      <el-col :span="6">
        <heartTab :schoolDataObj="schoolDataObj" :key="time" />
      </el-col>
      <el-col :span="12">
        <warningTab :schoolDataObj="schoolDataObj" />
      </el-col>
      <el-col :span="6">
        <heartWarningTab :schoolDataObj="schoolDataObj" />
      </el-col>
    </el-row>
  </basic-container>
</template>

<script>
import { mapGetters } from "vuex";
import heartTab from "./schoolBoard/heartTab";
import warningTab from "./schoolBoard/warningTab";
import heartWarningTab from "./schoolBoard/heartWarningTab";
import {
  findALLNum,
  findALLTestNum,
  findAllGradeLevelInterveneNum,
  findFinishNoTestNum,
  findFinishTestNum,
  findGradeLevelInterveneNum,
  findGradeLevelNum,
  findLevelAllNum,
  findLevelAreaNum,
  findLevelNum,
  findLevelSexNum,
  findSexLevelNum,
  findAllGradeNoTestNum,
  findGradeLevelNum1,
  totalTenantPostNumber,
  getTenant,
} from "@/api/report/report";
import { getCensusList } from "@/api/census";
export default {
  name: "thirdRegister",
  components: { heartTab, warningTab, heartWarningTab },
  data() {
    return {
      isLoad: false,
      schoolName: "",
      tenantId: "",
      projectId: "",
      time: "",
      projectOptions: [],
      schoolDataObj: {},
    };
  },
  computed: {
    ...mapGetters(["userInfo"]),
  },
  created() {},
  mounted() {
    this.initData();
    this.getProjectInfo();
  },
  methods: {
    searchProjectData() {
      this.isLoad = false;
      this.initData();
    },
    initData() {
      let tenantId = JSON.parse(window.localStorage.getItem("saber-userInfo"))
        .content.tenantId;
      if (this.$route.query.tenantId) {
        tenantId = this.$route.query.tenantId;
      }
      var _this = this; //注意！一定要重新定义一下this指向
      let projectId = this.projectId;
      this.$axios
        .all([
          findALLNum({ tenantId: tenantId, projectId: projectId }),
          findALLTestNum({ tenantId: tenantId, projectId: projectId }),
          findAllGradeLevelInterveneNum({
            tenantId: tenantId,
            projectId: projectId,
          }),
          findFinishNoTestNum({ tenantId: tenantId, projectId: projectId }),
          findFinishTestNum({ tenantId: tenantId, projectId: projectId }),
          findGradeLevelInterveneNum({
            tenantId: tenantId,
            projectId: projectId,
          }),
          findGradeLevelNum({ tenantId: tenantId, projectId: projectId }),
          findLevelAllNum({ tenantId: tenantId, projectId: projectId }),
          findLevelAreaNum({ tenantId: tenantId, projectId: projectId }),
          findLevelNum({ tenantId: tenantId, projectId: projectId }),
          findLevelSexNum({ tenantId: tenantId, projectId: projectId }),
          findSexLevelNum({ tenantId: tenantId, projectId: projectId }),
          findAllGradeNoTestNum({ tenantId: tenantId, projectId: projectId }),
          findGradeLevelNum1({ tenantId: tenantId, projectId: projectId }),
          getTenant(tenantId),
          totalTenantPostNumber({ tenantId: tenantId, category: 2 }),
          totalTenantPostNumber({ tenantId: tenantId, category: 4 }),
        ])
        .then(
          _this.$axios.spread(function (
            res1,
            res2,
            res3,
            res4,
            res5,
            res6,
            res7,
            res8,
            res9,
            res10,
            res11,
            res12,
            res13,
            res14,
            res15,
            res16,
            res17
          ) {
            _this.schoolDataObj.findALLNum = res1.data.data;
            _this.schoolDataObj.findALLTestNum = res2.data.data;
            _this.schoolDataObj.findAllGradeLevelInterveneNum = res3.data.data;
            _this.schoolDataObj.findFinishNoTestNum = res4.data.data;
            _this.schoolDataObj.findFinishTestNum = res5.data.data;
            _this.schoolDataObj.findGradeLevelInterveneNum = res6.data.data;
            _this.schoolDataObj.findGradeLevelNum = res7.data.data;
            _this.schoolDataObj.findLevelAllNum = res8.data.data;
            _this.schoolDataObj.findLevelAreaNum = res9.data.data;
            _this.schoolDataObj.findLevelNum = res10.data.data;
            _this.schoolDataObj.findLevelSexNum = res11.data.data;
            _this.schoolDataObj.findSexLevelNum = res12.data.data;
            _this.schoolDataObj.findAllGradeNoTestNum = res13.data.data;
            _this.schoolDataObj.findGradeLevelNum1 = res14.data.data;
            _this.schoolName = res15.data.data.tenantName;
            _this.schoolDataObj.totalTenantPostNumber = {};
            _this.schoolDataObj.totalTenantPostNumber.teacherNum =
              res16.data.data;
            _this.schoolDataObj.totalTenantPostNumber.studentNum =
              res17.data.data;
            _this.schoolDataObj.tenantId = tenantId;
            _this.isLoad = true;
          })
        );
    },
    handleDown() {
      this.$router.push({
        name: "年级详情列表",
        query: {
          projectId: this.projectId,
          tenantId: this.schoolDataObj.tenantId,
        },
      });
    },
    getProjectInfo() {
      let tenantId = JSON.parse(window.localStorage.getItem("saber-userInfo"))
        .content.tenantId;
      if (this.$route.query.tenantId) {
        tenantId = this.$route.query.tenantId;
      }
      getCensusList(1, 1000, { tenantId: tenantId }).then((res) => {
        this.projectOptions = res.data.data.records;
      });
    },
  },
};
</script>
<style lang="scss">
.tableTdCss {
  border: 1px solid white;
}
.headerCss {
  background: #29d;
  color: white;
}
.tableRowSingle {
  background: #ebeef5;
}
.tableRowDouble {
  background: #ecf5ff;
}
</style>
